package com.youlai.boot.modules.exhibition.controller;

import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import com.youlai.boot.modules.exhibition.model.ExhibitionShopForm;
import com.youlai.boot.modules.exhibition.model.ExhibitionShopVO;
import com.youlai.boot.modules.exhibition.service.ExhibitionShopService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

@Tag(name = "展会展商接口")
@RestController
@RequestMapping("/api/v1/exhibition-shop")
@RequiredArgsConstructor
public class ExhibitionShopController {

    private final ExhibitionShopService exhibitionShopService;

    @Operation(summary = "展会展商分页列表")
    @GetMapping("/page")
    public PageResult<ExhibitionShopVO> listExhibitionShops(
            @RequestParam(required = false) Long exhibitionId,
            @RequestParam(required = false) Long shopId,
            @RequestParam(required = false) Integer boothType,
            @RequestParam(required = false) Integer status,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        Page<ExhibitionShopVO> result = exhibitionShopService.getExhibitionShopPage(exhibitionId, shopId, boothType,
                status, pageNum, pageSize);
        return PageResult.success(result);
    }

    @Operation(summary = "展会展商详情")
    @GetMapping("/{id}")
    public Result<ExhibitionShopVO> getExhibitionShop(@PathVariable Long id) {
        ExhibitionShopVO exhibitionShop = exhibitionShopService.getExhibitionShopById(id);
        return Result.success(exhibitionShop);
    }

    @Operation(summary = "添加展会展商")
    @PostMapping
    public Result<Long> addExhibitionShop(@Valid @RequestBody ExhibitionShopForm exhibitionShop) {
        Long id = exhibitionShopService.saveExhibitionShop(exhibitionShop);
        return Result.success(id);
    }

    @Operation(summary = "修改展会展商")
    @PutMapping("/{id}")
    public Result<Boolean> updateExhibitionShop(
            @PathVariable Long id,
            @Valid @RequestBody ExhibitionShopForm exhibitionShop) {
        exhibitionShop.setId(id);
        exhibitionShopService.updateExhibitionShop(exhibitionShop);
        return Result.success(true);
    }

    @Operation(summary = "删除展会展商")
    @DeleteMapping("/{id}")
    public Result<Boolean> deleteExhibitionShop(@PathVariable Long id) {
        boolean result = exhibitionShopService.deleteExhibitionShop(id);
        return Result.judge(result);
    }
}